function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import memoizeOne from 'memoize-one';
import { createElement, PureComponent } from 'react';
import { flushSync } from 'react-dom';
import { getScrollBarInfo } from "../util";
import { cancelTimeout, requestTimeout } from "./common";
import { getRTLOffsetType } from "./domHelpers";
var IS_SCROLLING_DEBOUNCE_INTERVAL = 150;
var defaultItemKey = function defaultItemKey(_ref) {
  var columnIndex = _ref.columnIndex,
    rowIndex = _ref.rowIndex;
  return "".concat(rowIndex, ":").concat(columnIndex);
};

// In DEV mode, this Set helps us only log a warning once per component instance.
// This avoids spamming the console every time a render happens.
var devWarningsOverscanCount = null;
var devWarningsOverscanRowsColumnsCount = null;
var devWarningsTagName = null;
if (process.env.NODE_ENV !== 'production') {
  if (typeof window !== 'undefined' && typeof window.WeakSet !== 'undefined') {
    devWarningsOverscanCount = new WeakSet();
    devWarningsOverscanRowsColumnsCount = new WeakSet();
    devWarningsTagName = new WeakSet();
  }
}
export default function createGridComponent(_ref2) {
  var _class;
  var getColumnOffset = _ref2.getColumnOffset,
    getColumnStartIndexForOffset = _ref2.getColumnStartIndexForOffset,
    getColumnStopIndexForStartIndex = _ref2.getColumnStopIndexForStartIndex,
    getColumnWidth = _ref2.getColumnWidth,
    getEstimatedTotalHeight = _ref2.getEstimatedTotalHeight,
    getEstimatedTotalWidth = _ref2.getEstimatedTotalWidth,
    getOffsetForColumnAndAlignment = _ref2.getOffsetForColumnAndAlignment,
    getOffsetForRowAndAlignment = _ref2.getOffsetForRowAndAlignment,
    getRowHeight = _ref2.getRowHeight,
    getRowOffset = _ref2.getRowOffset,
    getRowStartIndexForOffset = _ref2.getRowStartIndexForOffset,
    getRowStopIndexForStartIndex = _ref2.getRowStopIndexForStartIndex,
    initInstanceProps = _ref2.initInstanceProps,
    shouldResetStyleCacheOnItemSizeChange = _ref2.shouldResetStyleCacheOnItemSizeChange;
  return _class = /*#__PURE__*/function (_PureComponent) {
    _inherits(Grid, _PureComponent);
    var _super = _createSuper(Grid);
    // Always use explicit constructor for React components.
    // It produces less code after transpilation. (#26)
    // eslint-disable-next-line no-useless-constructor
    function Grid(props) {
      var _this;
      _classCallCheck(this, Grid);
      _this = _super.call(this, props);
      //  this._shouldResetStyleCacheOnItemSizeChange = (props.itemData as any)?.table?.shouldResetStyleCacheOnItemSizeChange?.();
      _defineProperty(_assertThisInitialized(_this), "_instanceProps", initInstanceProps(_this.props, _assertThisInitialized(_this)));
      _defineProperty(_assertThisInitialized(_this), "_resetIsScrollingTimeoutId", null);
      _defineProperty(_assertThisInitialized(_this), "_outerRef", void 0);
      _defineProperty(_assertThisInitialized(_this), "_isTree", false);
      _defineProperty(_assertThisInitialized(_this), "_shouldResetStyleCacheOnItemSizeChange", shouldResetStyleCacheOnItemSizeChange);
      _defineProperty(_assertThisInitialized(_this), "state", {
        instance: _assertThisInitialized(_this),
        isScrolling: false,
        horizontalScrollDirection: 'forward',
        scrollLeft: typeof _this.props.initialScrollLeft === 'number' ? _this.props.initialScrollLeft : 0,
        scrollTop: typeof _this.props.initialScrollTop === 'number' ? _this.props.initialScrollTop : 0,
        scrollUpdateWasRequested: false,
        verticalScrollDirection: 'forward'
      });
      _defineProperty(_assertThisInitialized(_this), "_onScroll", function (event) {
        var _this$props$itemData;
        var _event$currentTarget = event.currentTarget,
          clientHeight = _event$currentTarget.clientHeight,
          clientWidth = _event$currentTarget.clientWidth,
          scrollLeft = _event$currentTarget.scrollLeft,
          scrollTop = _event$currentTarget.scrollTop,
          scrollHeight = _event$currentTarget.scrollHeight,
          scrollWidth = _event$currentTarget.scrollWidth;
        var scrollAsync = (_this$props$itemData = _this.props.itemData) === null || _this$props$itemData === void 0 || (_this$props$itemData = _this$props$itemData.table) === null || _this$props$itemData === void 0 || (_this$props$itemData = _this$props$itemData.props.optimize) === null || _this$props$itemData === void 0 ? void 0 : _this$props$itemData.scrollAsync;
        var wrap = scrollAsync ? function (fn) {
          return fn();
        } : flushSync; // 强制同步，防止header区域滚动延迟（react18）
        wrap(function () {
          return _this.setState(function (prevState) {
            if (prevState.scrollLeft === scrollLeft && prevState.scrollTop === scrollTop) {
              // Scroll position may have been updated by cDM/cDU,
              // In which case we don't need to trigger another render,
              // And we don't want to update state.isScrolling.
              return null;
            }
            var direction = _this.props.direction;

            // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
            // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
            // It's also easier for this component if we convert offsets to the same format as they would be in for ltr.
            // So the simplest solution is to determine which browser behavior we're dealing with, and convert based on it.
            var calculatedScrollLeft = scrollLeft;
            if (direction === 'rtl') {
              switch (getRTLOffsetType()) {
                case 'negative':
                  calculatedScrollLeft = -scrollLeft;
                  break;
                case 'positive-descending':
                  calculatedScrollLeft = scrollWidth - clientWidth - scrollLeft;
                  break;
              }
            }

            // Prevent Safari's elastic scrolling from causing visual shaking when scrolling past bounds.
            calculatedScrollLeft = Math.max(0, Math.min(calculatedScrollLeft, scrollWidth - clientWidth));
            var calculatedScrollTop = Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
            return {
              isScrolling: true,
              horizontalScrollDirection: prevState.scrollLeft < scrollLeft ? 'forward' : 'backward',
              scrollLeft: calculatedScrollLeft,
              scrollTop: calculatedScrollTop,
              verticalScrollDirection: prevState.scrollTop < scrollTop ? 'forward' : 'backward',
              scrollUpdateWasRequested: false
            };
          }, _this._resetIsScrollingDebounced);
        });
      });
      _defineProperty(_assertThisInitialized(_this), "_outerRefSetter", function (ref) {
        var outerRef = _this.props.outerRef;
        _this._outerRef = ref;
        if (typeof outerRef === 'function') {
          outerRef(ref);
        } else if (outerRef != null && _typeof(outerRef) === 'object' && outerRef.hasOwnProperty('current')) {
          outerRef.current = ref;
        }
      });
      _defineProperty(_assertThisInitialized(_this), "_callOnItemsRendered", memoizeOne(function (overscanColumnStartIndex, overscanColumnStopIndex, overscanRowStartIndex, overscanRowStopIndex, visibleColumnStartIndex, visibleColumnStopIndex, visibleRowStartIndex, visibleRowStopIndex) {
        var _this$props$onItemsRe, _this$props;
        return (_this$props$onItemsRe = (_this$props = _this.props).onItemsRendered) === null || _this$props$onItemsRe === void 0 ? void 0 : _this$props$onItemsRe.call(_this$props, {
          overscanColumnStartIndex: overscanColumnStartIndex,
          overscanColumnStopIndex: overscanColumnStopIndex,
          overscanRowStartIndex: overscanRowStartIndex,
          overscanRowStopIndex: overscanRowStopIndex,
          visibleColumnStartIndex: visibleColumnStartIndex,
          visibleColumnStopIndex: visibleColumnStopIndex,
          visibleRowStartIndex: visibleRowStartIndex,
          visibleRowStopIndex: visibleRowStopIndex
        });
      }));
      _defineProperty(_assertThisInitialized(_this), "_callOnScroll", memoizeOne(function (scrollLeft, scrollTop, horizontalScrollDirection, verticalScrollDirection, scrollUpdateWasRequested) {
        var _this$props$onScroll, _this$props2;
        return (_this$props$onScroll = (_this$props2 = _this.props).onScroll) === null || _this$props$onScroll === void 0 ? void 0 : _this$props$onScroll.call(_this$props2, {
          horizontalScrollDirection: horizontalScrollDirection,
          scrollLeft: scrollLeft,
          scrollTop: scrollTop,
          verticalScrollDirection: verticalScrollDirection,
          scrollUpdateWasRequested: scrollUpdateWasRequested
        });
      }));
      _defineProperty(_assertThisInitialized(_this), "_getItemStyle", function (rowIndex, columnIndex) {
        var _this$props3 = _this.props,
          columnWidth = _this$props3.columnWidth,
          direction = _this$props3.direction,
          rowHeight = _this$props3.rowHeight;
        var itemStyleCache = _this._getItemStyleCache(_this._shouldResetStyleCacheOnItemSizeChange && columnWidth, _this._shouldResetStyleCacheOnItemSizeChange && direction, _this._shouldResetStyleCacheOnItemSizeChange && rowHeight);
        var key = "".concat(rowIndex, ":").concat(columnIndex);
        var style;
        if (itemStyleCache.hasOwnProperty(key)) {
          style = itemStyleCache[key];
        } else {
          var offset = getColumnOffset(_this.props, columnIndex, _this._instanceProps);
          var isRtl = direction === 'rtl';
          itemStyleCache[key] = style = {
            position: 'absolute',
            left: isRtl ? undefined : offset,
            right: isRtl ? offset : undefined,
            top: getRowOffset(_this.props, rowIndex, _this._instanceProps),
            height: getRowHeight(_this.props, rowIndex, _this._instanceProps),
            width: getColumnWidth(_this.props, columnIndex, _this._instanceProps)
          };
        }
        return style;
      });
      _defineProperty(_assertThisInitialized(_this), "_getItemStyleCache", memoizeOne(function (_, __, ___) {
        return {};
      }));
      _defineProperty(_assertThisInitialized(_this), "_resetIsScrolling", function () {
        var _me$props$itemData;
        var me = _assertThisInitialized(_this);
        me._resetIsScrollingTimeoutId = null;
        (_me$props$itemData = me.props.itemData) === null || _me$props$itemData === void 0 || (_me$props$itemData = _me$props$itemData.table) === null || _me$props$itemData === void 0 || _me$props$itemData._resetRowHeight({
          immediate: false
        });
        _this.setState({
          isScrolling: false
        }, function () {
          // Clear style cache after state update has been committed.
          // This way we don't break pure sCU for items that don't use isScrolling param.
          _this._getItemStyleCache(-1);
        });
      });
      _defineProperty(_assertThisInitialized(_this), "_resetIsScrollingDebounced", function () {
        if (_this._resetIsScrollingTimeoutId !== null) {
          cancelTimeout(_this._resetIsScrollingTimeoutId);
        }
        _this._resetIsScrollingTimeoutId = requestTimeout(_this._resetIsScrolling, IS_SCROLLING_DEBOUNCE_INTERVAL);
      });
      return _this;
    }
    _createClass(Grid, [{
      key: "scrollTo",
      value: function scrollTo(_ref3) {
        var scrollLeft = _ref3.scrollLeft,
          scrollTop = _ref3.scrollTop;
        if (scrollLeft !== undefined) {
          scrollLeft = Math.max(0, scrollLeft);
        }
        if (scrollTop !== undefined) {
          scrollTop = Math.max(0, scrollTop);
        }
        this.setState(function (prevState) {
          if (scrollLeft === undefined) {
            scrollLeft = prevState.scrollLeft;
          }
          if (scrollTop === undefined) {
            scrollTop = prevState.scrollTop;
          }
          if (prevState.scrollLeft === scrollLeft && prevState.scrollTop === scrollTop) {
            return null;
          }
          return {
            horizontalScrollDirection: prevState.scrollLeft < scrollLeft ? 'forward' : 'backward',
            scrollLeft: scrollLeft,
            scrollTop: scrollTop,
            scrollUpdateWasRequested: true,
            verticalScrollDirection: prevState.scrollTop < scrollTop ? 'forward' : 'backward'
          };
        }, this._resetIsScrollingDebounced);
      }
    }, {
      key: "scrollLeftAndTop",
      value: function scrollLeftAndTop(_ref4, callback) {
        var _this2 = this;
        var _ref4$left = _ref4.left,
          left = _ref4$left === void 0 ? 0 : _ref4$left,
          _ref4$top = _ref4.top,
          top = _ref4$top === void 0 ? 0 : _ref4$top;
        var _this$_outerRef = this._outerRef,
          scrollHeight = _this$_outerRef.scrollHeight,
          scrollWidth = _this$_outerRef.scrollWidth,
          clientHeight = _this$_outerRef.clientHeight,
          clientWidth = _this$_outerRef.clientWidth;
        var maxScrollLeft = scrollWidth - clientWidth,
          maxScrollTop = scrollHeight - clientHeight;
        this.setState(function (prevState) {
          var _ref5 = [Math.min(prevState.scrollLeft + left, maxScrollLeft), Math.min(prevState.scrollTop + top, maxScrollTop)],
            scrollLeft = _ref5[0],
            scrollTop = _ref5[1];
          if (prevState.scrollLeft === scrollLeft && prevState.scrollTop === scrollTop) {
            return null;
          }
          if (maxScrollTop === scrollTop) {
            scrollTop = 0;
          }
          if (maxScrollLeft === scrollLeft) {
            scrollLeft = 0;
          }
          return {
            horizontalScrollDirection: prevState.scrollLeft < scrollLeft ? 'forward' : 'backward',
            scrollLeft: scrollLeft,
            scrollTop: scrollTop,
            scrollUpdateWasRequested: true,
            verticalScrollDirection: prevState.scrollTop < scrollTop ? 'forward' : 'backward'
          };
        }, function () {
          _this2._resetIsScrollingDebounced();
          var _this2$state = _this2.state,
            scrollLeft = _this2$state.scrollLeft,
            scrollTop = _this2$state.scrollTop;
          callback === null || callback === void 0 || callback({
            left: scrollLeft === maxScrollLeft,
            top: maxScrollTop === scrollTop
          });
        });
      }
    }, {
      key: "scrollToItem",
      value: function scrollToItem(_ref6) {
        var _ref6$align = _ref6.align,
          align = _ref6$align === void 0 ? 'auto' : _ref6$align,
          columnIndex = _ref6.columnIndex,
          rowIndex = _ref6.rowIndex;
        var _this$props4 = this.props,
          columnCount = _this$props4.columnCount,
          height = _this$props4.height,
          rowCount = _this$props4.rowCount,
          width = _this$props4.width;
        var _this$state = this.state,
          scrollLeft = _this$state.scrollLeft,
          scrollTop = _this$state.scrollTop;
        var scrollbarSize = getScrollBarInfo();
        if (columnIndex !== undefined) {
          columnIndex = Math.max(0, Math.min(columnIndex, columnCount - 1));
        }
        if (rowIndex !== undefined) {
          rowIndex = Math.max(0, Math.min(rowIndex, rowCount - 1));
        }
        var estimatedTotalHeight = getEstimatedTotalHeight(this.props, this._instanceProps);
        var estimatedTotalWidth = getEstimatedTotalWidth(this.props, this._instanceProps);

        // The scrollbar size should be considered when scrolling an item into view,
        // to ensure it's fully visible.
        // But we only need to account for its size when it's actually visible.
        var horizontalScrollbarSize = estimatedTotalWidth > width ? scrollbarSize.width : 0;
        var verticalScrollbarSize = estimatedTotalHeight > height ? scrollbarSize.height : 0;
        this.scrollTo({
          scrollLeft: columnIndex !== undefined ? getOffsetForColumnAndAlignment(this.props, columnIndex, align, scrollLeft, this._instanceProps, verticalScrollbarSize) : scrollLeft,
          scrollTop: rowIndex !== undefined ? getOffsetForRowAndAlignment(this.props, rowIndex, align, scrollTop, this._instanceProps, horizontalScrollbarSize) : scrollTop
        });
      }
    }, {
      key: "componentDidMount",
      value: function componentDidMount() {
        var _this$props5 = this.props,
          initialScrollLeft = _this$props5.initialScrollLeft,
          initialScrollTop = _this$props5.initialScrollTop;
        if (this._outerRef != null) {
          var outerRef = this._outerRef;
          if (typeof initialScrollLeft === 'number') {
            outerRef.scrollLeft = initialScrollLeft;
          }
          if (typeof initialScrollTop === 'number') {
            outerRef.scrollTop = initialScrollTop;
          }
        }
        this._callPropsCallbacks();
      }
    }, {
      key: "componentDidUpdate",
      value: function componentDidUpdate() {
        var direction = this.props.direction;
        var _this$state2 = this.state,
          scrollLeft = _this$state2.scrollLeft,
          scrollTop = _this$state2.scrollTop,
          scrollUpdateWasRequested = _this$state2.scrollUpdateWasRequested;
        if (scrollUpdateWasRequested && this._outerRef != null) {
          // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.
          // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left).
          // So we need to determine which browser behavior we're dealing with, and mimic it.
          var outerRef = this._outerRef;
          if (direction === 'rtl') {
            switch (getRTLOffsetType()) {
              case 'negative':
                outerRef.scrollLeft = -scrollLeft;
                break;
              case 'positive-ascending':
                outerRef.scrollLeft = scrollLeft;
                break;
              default:
                var clientWidth = outerRef.clientWidth,
                  scrollWidth = outerRef.scrollWidth;
                outerRef.scrollLeft = scrollWidth - clientWidth - scrollLeft;
                break;
            }
          } else {
            outerRef.scrollLeft = Math.max(0, scrollLeft);
          }
          outerRef.scrollTop = Math.max(0, scrollTop);
        }
        this._callPropsCallbacks();
      }
    }, {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        if (this._resetIsScrollingTimeoutId !== null) {
          cancelTimeout(this._resetIsScrollingTimeoutId);
        }
      }
    }, {
      key: "render",
      value: function render() {
        var _this$props6 = this.props,
          children = _this$props6.children,
          className = _this$props6.className,
          columnCount = _this$props6.columnCount,
          direction = _this$props6.direction,
          height = _this$props6.height,
          innerRef = _this$props6.innerRef,
          innerElementType = _this$props6.innerElementType,
          innerTagName = _this$props6.innerTagName,
          itemData = _this$props6.itemData,
          _this$props6$itemKey = _this$props6.itemKey,
          itemKey = _this$props6$itemKey === void 0 ? defaultItemKey : _this$props6$itemKey,
          outerElementType = _this$props6.outerElementType,
          outerTagName = _this$props6.outerTagName,
          rowCount = _this$props6.rowCount,
          style = _this$props6.style,
          useIsScrolling = _this$props6.useIsScrolling,
          width = _this$props6.width;
        var isScrolling = this.state.isScrolling;
        var _this$_getHorizontalR = this._getHorizontalRangeToRender(),
          _this$_getHorizontalR2 = _slicedToArray(_this$_getHorizontalR, 2),
          columnStartIndex = _this$_getHorizontalR2[0],
          columnStopIndex = _this$_getHorizontalR2[1];
        var _this$_getVerticalRan = this._getVerticalRangeToRender(),
          _this$_getVerticalRan2 = _slicedToArray(_this$_getVerticalRan, 2),
          rowStartIndex = _this$_getVerticalRan2[0],
          rowStopIndex = _this$_getVerticalRan2[1];
        var items = [];
        if (columnCount > 0 && rowCount) {
          for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
            for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
              items.push( /*#__PURE__*/createElement(children, {
                columnIndex: columnIndex,
                data: itemData,
                isScrolling: useIsScrolling ? isScrolling : undefined,
                key: itemKey({
                  columnIndex: columnIndex,
                  data: itemData,
                  rowIndex: rowIndex
                }),
                rowIndex: rowIndex,
                style: this._getItemStyle(rowIndex, columnIndex)
              }));
            }
          }
        }

        // Read this value AFTER items have been created,
        // So their actual sizes (if variable) are taken into consideration.
        var estimatedTotalHeight = getEstimatedTotalHeight(this.props, this._instanceProps);
        var estimatedTotalWidth = getEstimatedTotalWidth(this.props, this._instanceProps);
        return /*#__PURE__*/createElement(outerElementType || outerTagName || 'div', {
          className: className,
          onScroll: this._onScroll,
          ref: this._outerRefSetter,
          style: _objectSpread({
            position: 'relative',
            height: height,
            width: width,
            overflow: 'auto',
            WebkitOverflowScrolling: 'touch',
            willChange: 'transform',
            direction: direction
          }, style)
        }, /*#__PURE__*/createElement(innerElementType || innerTagName || 'div', {
          children: items,
          ref: innerRef,
          style: {
            height: estimatedTotalHeight,
            pointerEvents: isScrolling ? 'none' : undefined,
            width: estimatedTotalWidth
          }
        }));
      }
    }, {
      key: "_getHorizontalRangeToRender",
      value: function _getHorizontalRangeToRender() {
        var _this$props7 = this.props,
          columnCount = _this$props7.columnCount,
          overscanColumnCount = _this$props7.overscanColumnCount,
          overscanColumnsCount = _this$props7.overscanColumnsCount,
          overscanCount = _this$props7.overscanCount,
          rowCount = _this$props7.rowCount;
        var scrollLeft = this.state.scrollLeft;
        var overscanCountResolved = overscanColumnCount || overscanColumnsCount || overscanCount || 1;
        if (columnCount === 0 || rowCount === 0) {
          return [0, 0, 0, 0];
        }
        var startIndex = getColumnStartIndexForOffset(this.props, scrollLeft, this._instanceProps);
        var stopIndex = getColumnStopIndexForStartIndex(this.props, startIndex, scrollLeft, this._instanceProps);
        return [Math.max(0, startIndex - overscanCountResolved), Math.max(0, Math.min(columnCount - 1, stopIndex + overscanCountResolved)), startIndex, stopIndex];
      }
    }, {
      key: "_getVerticalRangeToRender",
      value: function _getVerticalRangeToRender() {
        var _this$props8 = this.props,
          columnCount = _this$props8.columnCount,
          overscanCount = _this$props8.overscanCount,
          overscanRowCount = _this$props8.overscanRowCount,
          overscanRowsCount = _this$props8.overscanRowsCount,
          rowCount = _this$props8.rowCount;
        var scrollTop = this.state.scrollTop;
        var overscanCountResolved = overscanRowCount || overscanRowsCount || overscanCount || 1;
        if (columnCount === 0 && rowCount === 0) {
          return [0, 0, 0, 0];
        }
        var startIndex = getRowStartIndexForOffset(this.props, scrollTop, this._instanceProps);
        var stopIndex = getRowStopIndexForStartIndex(this.props, startIndex, scrollTop, this._instanceProps);
        return [Math.max(0, startIndex - overscanCountResolved), Math.max(0, Math.min(rowCount - 1, stopIndex + overscanCountResolved)), startIndex, stopIndex];
      }
    }, {
      key: "_callPropsCallbacks",
      value: function _callPropsCallbacks() {
        var _this$props9 = this.props,
          columnCount = _this$props9.columnCount,
          onItemsRendered = _this$props9.onItemsRendered,
          onScroll = _this$props9.onScroll,
          rowCount = _this$props9.rowCount;
        if (typeof onItemsRendered === 'function') {
          if (columnCount > 0 && rowCount > 0) {
            var _this$_getHorizontalR3 = this._getHorizontalRangeToRender(),
              _this$_getHorizontalR4 = _slicedToArray(_this$_getHorizontalR3, 4),
              overscanColumnStartIndex = _this$_getHorizontalR4[0],
              overscanColumnStopIndex = _this$_getHorizontalR4[1],
              visibleColumnStartIndex = _this$_getHorizontalR4[2],
              visibleColumnStopIndex = _this$_getHorizontalR4[3];
            var _this$_getVerticalRan3 = this._getVerticalRangeToRender(),
              _this$_getVerticalRan4 = _slicedToArray(_this$_getVerticalRan3, 4),
              overscanRowStartIndex = _this$_getVerticalRan4[0],
              overscanRowStopIndex = _this$_getVerticalRan4[1],
              visibleRowStartIndex = _this$_getVerticalRan4[2],
              visibleRowStopIndex = _this$_getVerticalRan4[3];
            this._callOnItemsRendered(overscanColumnStartIndex, overscanColumnStopIndex, overscanRowStartIndex, overscanRowStopIndex, visibleColumnStartIndex, visibleColumnStopIndex, visibleRowStartIndex, visibleRowStopIndex);
          }
        }
        if (typeof onScroll === 'function') {
          var _this$state3 = this.state,
            horizontalScrollDirection = _this$state3.horizontalScrollDirection,
            scrollLeft = _this$state3.scrollLeft,
            scrollTop = _this$state3.scrollTop,
            scrollUpdateWasRequested = _this$state3.scrollUpdateWasRequested,
            verticalScrollDirection = _this$state3.verticalScrollDirection;
          this._callOnScroll(scrollLeft, scrollTop, horizontalScrollDirection, verticalScrollDirection, scrollUpdateWasRequested);
        }
      }
    }]);
    return Grid;
  }(PureComponent), _defineProperty(_class, "defaultProps", {
    direction: 'ltr',
    itemData: undefined,
    useIsScrolling: false
  }), _class;
}